<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #box{
            width: 500px;
            height: 100px;
            border: 2px solid rosybrown;
        }
    </style>
</head>
<body>
    <input type="text">&nbsp;
    <button onclick="copy()">复制</button>
    <div id="box">
        
    </div>
    <script>
        function copy() {
            var div = document.querySelector('#box')
            if (div.childElementCount>0) {
                var h1=document.querySelector('h1')
                div.removeChild(h1)
            }
            var txt = document.querySelector('input').value
            var newH2= document.createElement('h1')
            var text = document.createTextNode(txt)
            newH2.appendChild(text)
            div.appendChild(newH2)

        }
    </script>
</body>
</html>